<template>
	<view class="container">
		<view class="text">预约时间</view>
		<view class="input-box" @tap="selecttime">
			<input type="text" disabled="true" class="input-btn" :value="value" placeholder-style="font-size: 28rpx;font-weight: normal;font-stretch: normal;line-height: 60rpx;letter-spacing: 0rpx;color: #c3c3c3;"
			 placeholder="请选择符合配送范围的送件时间">
			<view class="right-icon">
				<image src="../../../static/images/right.png" class="right-img"></image>
			</view>
		</view>
		<w-picker 
		    mode="limit" 
		    dayStep="365"
		    :startHour="starttime"
		    :endHour="endtime"
		    minuteStep="1"
		    afterStep="30"
		    @confirm="onConfirm" 
		    ref="limit" 
		    themeColor="#f00">
		</w-picker>
		<view class="title">物业代送时间为{{time.start_time}}至{{time.end_time}}<text class="text-after">代送费用{{money}}</text></view>
		<button type="primary" :style="btn_style" class="btn" @click="btnpay">确定</button>
	</view>
</template>

<script>
	import wPicker from "../component/w-picker/w-picker.vue";
	var common = require('../../../utils/common.js');
	var app = getApp();
	var _this;
	const getappointTime = () => {
		common.post('HouseApi&a=express_appoint_add', {
			village_id: _this.village_id,
			pigcms_id: _this.pigcms_id,
			send_time: _this.value,
			express_id: _this.id,
			express_collection_price: _this.price
		}, data => {
			console.log('++++', data)
			common.parseUrl(data.order_url)
		});
	};
	const getTime = () => {
		common.post('HouseApi&a=express_type_time', {
			village_id: _this.village_id,
		}, data => {
			console.log('++++', data)
			_this.time = data;
			_this.starttime = Number(data.start_time.substring(0,2)) 
			_this.endtime = Number(data.end_time.substring(0,2))
			console.log(typeof(_this.starttime))
			console.log('_this.endtime', _this.endtime)
		});
	};
	export default {
		data() {
			return {
				listdata: {},
				village_id: 0,
				pigcms_id: 0,
				actcolor: '',
				btn_style: '',
				value: '',
				id: 0,
				price: 0,
				time:'',
				money: '',
				starttime: 0,
				endtime: 0,
			}
		},
		onShow() {
			// #ifdef H5
			common.hideWxShare()
			// #endif
		},
		onLoad(options) {
			_this = this;
			_this.id = options.id;
			_this.money = options.money;
			_this.price = options.price;
			// #ifdef H5
			console.log('准备跳小程序页', _this.id);
			common.webToMiniapp(_this.route, options, 'redirect')
			// #endif

			common.setMainColor(_this, function(config) {
				_this.actcolor = config.config.mobile_head_color
				_this.btn_style = 'background-color: ' + _this.actcolor + ';box-shadow:0px 30rpx 30rpx -30rpx ' + _this.actcolor +
					';';

				const res = uni.getStorageSync('village_key');
				if (res) {
					_this.village_id = res.village_id;
					_this.pigcms_id = res.pigcms_id;
					_this.village_name = res.village_name;
				};
				getTime()
			});
		},
		methods: {
			selecttime(){
				this.$refs.limit.show()
			},
			onConfirm(val){
				_this.value = val.result
			},
			btnpay(){
				if(_this.value){
					getappointTime();
				}else{
					uni.showModal({
						title: common.changeTxt('提示'),
						content: common.changeTxt('预约时间不能为空'),
						showCancel: false,
						confirmText: common.changeTxt('确定'),
						success: function(res) {
							if (res.confirm) {
								
							}
						}
					});
				}
			},
		},
		components: {
			wPicker
		}
	}
</script>

<style>
	page {
		background: rgb(245, 245, 245);
	}

	.container {
		margin: 0;
		padding: 0;
	}

	.text {
		font-size: 26rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 60rpx;
		letter-spacing: 0rpx;
		color: #333333;
		margin-left: 30rpx;
		margin-top: 30rpx;
	}

	.input-box {
		margin: 15rpx 30rpx 10rpx 30rpx;
		padding: 30rpx;
		background-color: #ffffff;
		box-shadow: 0px 2rpx 11rpx 2rpx rgba(227, 227, 227, 0.33);
		border-radius: 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.input-btn {
		width: 100%;
	}

	.right-icon {
		width: 30rpx;
		height: 30rpx;
	}

	.right-img {
		width: 100%;
		height: 100%;
		display: block;
	}
	.title {
		font-size: 22rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 60rpx;
		letter-spacing: 0rpx;
		color: #999999;
		text-align: center;
	}
	.text-after {
		font-size: 22rpx;
		font-weight: normal;
		letter-spacing: 0rpx;
		color: #f04517;
	}
	.btn {
		font-size: 32rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 90rpx;
		letter-spacing: 0px;
		color: #ffffff;
		background-color: #2681f3;
		border-radius: 44rpx;
		margin: 0rpx 100rpx;
		margin-top: 400rpx;
		border: 0rpx;
	}
</style>
